<?php
namespace core\lib;

class config
{

    static public $conf = array();//配置文件数组

    /**
     * 获取配置文件中单个的配置
     * 1：判断配置文件是否存在
     * 2：判断配置是否存在
     * 3：缓存配置
     * @param $name string 配置名
     * @param $file string 配置文件名
     * @return mixed
     * @throws \Exception
     */
    static public function getConfig($name, $file)
    {


        if (isset(self::$conf[$file])) {
            return self::$conf[$file][$name];
        } else {
            //拼接配置文件路径
            $filePath = BS . "/core/config/" . $file . '.php';

            if (is_file($filePath)) {
                $confPath = include $filePath;
                if (isset($confPath[$name])) {
                    self::$conf[$file] = $confPath;
                    return $confPath[$name];
                } else {
                    throw new \Exception('没有有这个配置项' . $name);
                }

            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }

    }

    //获取配置文件中所有的配置
    static public function getAll($file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else {
            $filePath = BS . "/core/config/" . $file . '.php';

            if (is_file($filePath)) {
                $confPath = include $filePath;
                self::$conf[$file] = $confPath;
                return $confPath;
            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }

    }
}